import { ENUM_VIEW } from '../../../schema/constants';

/**
 * 初始化高级筛选条件的API地址
 * @type {String}
 */
export const INITIALIZE_CONDITION_URL = ('/api/condition');
export const INITIALIZE_CONDITION_URL_SYMBOL = Symbol(INITIALIZE_CONDITION_URL);

/**
 * 设置高级筛选条件
 * @type {String}
 */
export const SET_CONDITION = 'set condition';

/**
 * 清除已选择的条件筛选项
 * @type {String}
 */
export const CLEAR_CONDITION = 'clear selected condition';

/**
 * 初始化过滤条件, 发起请求
 * @type {String}
 */
export const INIT_CONDITION_REQUEST = 'initialize the filter condition request';
/**
 * 请求数据成功
 * @type {String}
 */
export const INIT_CONDITION_SUCCESS = 'initialize the filter condition success';
/**
 * 请求数据失败
 * @type {String}
 */
export const INIT_CONDITION_FAILURE = 'initialize the filter condition failure';

/**
 * 设置条件 
 * @param  {String} key 条件键名
 * @param  {Object} value   条件值
 * @return {Object}         Action描述
 */
export const setCondition = (key = '', value) => ({
	type: SET_CONDITION,
	payload: {
		key,
		value
	}
});

/**
 * 清除所有条件筛选项
 * @param  {String} key 条件键名
 * @return {[type]} [description]
 */
export const clearCondition = (key) => ({
	type: CLEAR_CONDITION,
	payload: {
		key
	}
});

/**
 * 初始化查询条件
 * @return {Object} Action描述
 */
export const initConditionRequest = (key, value) => ({
	type: [ INIT_CONDITION_REQUEST, INIT_CONDITION_SUCCESS, INIT_CONDITION_FAILURE ],
	payload: {
		key,
		[INITIALIZE_CONDITION_URL_SYMBOL]: `${INITIALIZE_CONDITION_URL}/${key}/${value||''}`
	}
});

/**
 * 初始化成功
 * @param  {Object} data 获取回来的数据
 * @return {Object}      Action描述
 */
export const initConditionSuccess = (data) => ({
	type: INIT_CONDITION_SUCCESS,
	payload: { data }
});

/**
 * 初始化失败
 * @param  {String} error 失败的错误信息
 * @return {Object}       Action描述
 */
export const initConditionFailure = () => ({
	type: INIT_CONDITION_FAILURE,
});